package com.jmpt.fangbohui.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jmpt.fangbohui.R;
import com.jmpt.fangbohui.bean.HouseMoreSeleteCategoryBean;

import java.util.ArrayList;
import java.util.List;

public class BrokerAgentFilterRightAdapter extends BaseAdapter {

    public List<HouseMoreSeleteCategoryBean> data = new ArrayList<HouseMoreSeleteCategoryBean>();
    private Context mContext;
    private Drawable mDrawable;

    public BrokerAgentFilterRightAdapter(Context context) {
        mContext = context;
        mDrawable = context.getResources().getDrawable(R.drawable.ic_arrow_right_gray);
        mDrawable.setBounds(0, 0, mDrawable.getMinimumWidth(), mDrawable.getMinimumHeight());
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {

        if (view == null) {
            view = View.inflate(mContext, R.layout.item_list_home_selete_right, null);
        }
        HouseMoreSeleteCategoryBean bean = data.get(position);
        Holder holder = getHolder(view);
        holder.name.setText(bean.name);
        
        if (bean.isSelete) {
        	holder.name.setBackgroundColor(mContext.getResources().getColor(R.color.background_gray2));
        } else {
        	holder.name.setTextColor(mContext.getResources().getColor(R.color.font_black));
        	holder.name.setBackgroundResource(R.drawable.common_hover);
        }
        
        if (bean.values != null) {
        	//显示有子分类数据图标
        	holder.name.setCompoundDrawables(null, null, position == 0 ? null: mDrawable, null);
            if (bean.childSelete > -1) {
            	//之分类有被选中  显示红色字体
                holder.name.setTextColor(mContext.getResources().getColor(R.color.main_tab_font_selete));
            }else {
                holder.name.setTextColor(mContext.getResources().getColor(R.color.font_black));
            }
        } else {
            holder.name.setBackgroundResource(R.drawable.common_hover);
            holder.name.setCompoundDrawables(null, null, null, null);
        }
        
        return view;
    }

    private Holder getHolder(final View view) {
        Holder holder = (Holder) view.getTag();
        if (holder == null) {
            holder = new Holder(view);
            view.setTag(holder);
        }
        return holder;
    }

    class Holder {
        private TextView name;
        public Holder(View view) {
            name = (TextView) view.findViewById(R.id.name);
        }
    }
}
